using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for clsCategory
/// </summary>
public class clsCategory
{
    private int _id;

    public int Id
    {
        get { return _id; }
        set { _id = value; }
    }
    private string _name;

    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
    private int _parents_id;

    public int Parents_id
    {
        get { return _parents_id; }
        set { _parents_id = value; }
    }
    private int _count;

    public int Count
    {
        get { return _count; }
        set { _count = value; }
    }
    private int _order;

    public int Order
    {
        get { return _order; }
        set { _order = value; }
    }
    private int _level;

    public int Level
    {
        get { return _level; }
        set { _level = value; }
    }
    private string _pic_url;

    public string Pic_url
    {
        get { return _pic_url; }
        set { _pic_url = value; }
    }
    private string _keyword;

    public string Keyword
    {
        get { return _keyword; }
        set { _keyword = value; }
    }

    public clsCategory()
    { 
    }
    public DataTable getlistChildren(int id)
    {
        DBconnect connet = new DBconnect();
        connet.Open();
        if (connet.IsConnected == false)
            return null;        
        DataTable tmp = new DataTable();        
        string sql = "SELECT * FROM categories WHERE parents_id = "+ id;
        tmp = connet.GetDataTable(sql);
        connet.Close();
        return tmp;
    }
    public DataTable GetItem(int ID)
    {
        DBconnect connet = new DBconnect();
        connet.Open();
        if (connet.IsConnected == false)
            return null;    
        DataTable tblItem = new DataTable();       
        tblItem = connet.GetDataTable("SELECT * FROM categories WHERE ID=" + ID);
        connet.Close();
        return tblItem;
    }
    public bool insertItem()
    {
        DBconnect connect = new DBconnect();
        connect.Open();
        if (connect.IsConnected == false)
            return false;
        bool result = false;

        string[] listcol = new string[] { "name", "parents_id", "count", "level", "pic_url", "keywords", "order"};
        object[] listvalue = new object[] {this.Name, this.Parents_id, this.Count, this.Level, this.Pic_url, this.Keyword, this.Order};
        int i = connect.Insert("categories", listcol, listvalue);
        if (i > 0)
            result = true;
        connect.Close();
        return result;

    }

    public bool updateItem()
    {
        DBconnect connet = new DBconnect();
        connet.Open();
        bool result = false;
        string[] listcol = new string[] { "name", "parents_id", "pic_url", "keywords" };
        object[] listvalue = new object[] { this.Name, this.Parents_id, this.Pic_url, this.Keyword };
        string condition = "ID=@ID";
        object[] paramCondi = new object[] { "@ID", this.Id };
        int rs = connet.Update("categories", listcol, listvalue, condition, paramCondi);
        if (rs > 0)
            result = true;
        connet.Close();
        return result;
    }
    public bool deleteItem(int id)
    {
        DBconnect connect = new DBconnect();
        connect.Open();
        bool result = false;
        if (connect.Delete("categories", "ID=@ID", new object[] { "@ID", id }) > 0)
            result = true;
        connect.Close();
        return result;
    }

}
